package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Cases;
import cn.wolfcode.crm.page.PageResult;
import cn.wolfcode.crm.query.CasesQueryObject;
import cn.wolfcode.crm.service.ICasesService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.PermissionName;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.crypto.hash.Hash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("cases")
public class CasesController {

    @Autowired
    private ICasesService casesService;

    @RequestMapping("")
    @RequiresPermissions("cases:index")
    @PermissionName("报案表列表")
    public String index() {
        //只负责跳转到cases.jsp页面即可
        return "cases";
    }
    @RequestMapping("list")
    @RequiresPermissions("cases:list")
    @PermissionName("报案表数据")
    @ResponseBody
    public PageResult list(CasesQueryObject qo) {
        PageResult result=casesService.query(qo);
        return result;
    }
    @RequestMapping("save")
    @RequiresPermissions("cases:save")
    @PermissionName("报案表保存")
    @ResponseBody
    public JsonResult save(Cases cases) {
        JsonResult result = new JsonResult();
        try {
            casesService.save(cases);
        } catch (Exception e) {
            e.printStackTrace();
            result.mark("保存失败!!!");
        }
        return result;
    }
    @RequestMapping("update")
    @RequiresPermissions("cases:update")
    @PermissionName("报案表更新")
    @ResponseBody
    public JsonResult update(Cases cases) {
        JsonResult result = new JsonResult();
        try {
            casesService.update(cases);
        } catch (Exception e) {
            e.printStackTrace();
            result.mark("保存失败!!!");
        }
        return result;
    }
    @RequestMapping("searchState")
    @ResponseBody
    public Map<String,Object> searchState(String policySn) {
        Map<String, Object> map = new HashMap<>();
        try {
            String state=casesService.searchStateBypolicySn(policySn);
            map.put("success",true);
            map.put("msg",state);
        } catch (Exception e) {
            e.printStackTrace();
            map.put("success",false);
            map.put("msg","保单不存在");
        }
        return map;
    }



}